#include <iostream>
#include "node.h"

using namespace std;

Node::Node()
{
	x = 0;
	y = 0;
	f = 0;
	g = 0;
	h = 0;
	parent = 0;
}


Node::Node(int cx, int cy)
{
	x = cx;
	y = cy;
	f = 0;
	g = 0;
	h = 0;
	parent = 0;
}

bool Node::lessThanByF (Node& other)
{
	if(this->getF() < other.getF())
	{
		return true;
	}
	else if(this->getF() > other.getF())
	{
		return false;
	}
	else
	{
		if(this->getX() < other.getX())
		{
			return true;
		}
		else if(this->getX() > other.getX())
		{
			return false;
		}
		else
		{
			if(this->getY() < other.getY())
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
}

bool Node::greaterThanByF (Node& other)
{
	if(this->getF() > other.getF())
	{
		return true;
	}
	else if(this->getF() < other.getF())
	{
		return false;
	}
	else
	{
		if(this->getX() > other.getX())
		{
			return true;
		}
		else if(this->getX() < other.getX())
		{
			return false;
		}
		else
		{
			if(this->getY() > other.getY())
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
}

bool Node::lessThanByXY (int x, int y)
{
	if(this->getX() < x)
	{
		return true;
	}
	else if(this->getX() > x)
	{
		return false;
	}
	else
	{
		if(this->getY() < y)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

bool Node::greaterThanByXY (int x, int y)
{
	if(this->getX() > x)
	{
		return true;
	}
	else if(this->getX() < x)
	{
		return false;
	}
	else
	{
		if(this->getY() > y)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

bool Node::equalByF (Node& other)
{
	return this->f == other.getF() && this->x == other.getX() && this->x == other.getY();
}

bool Node::equalByXY (int x, int y)
{
	return this->x == x && this->x == y;
}

void Node::setX(int _x)
{
	x = _x;
}

void Node::setY(int _y)
{
	y = _y;
}

void Node::setF(float _f)
{
	f = _f;
}

void Node::setG(float _g)
{
	g = _g;
}

void Node::setH(float _h)
{
	h = _h;
}

int Node::getX()
{
	return x;
}

int Node::getY()
{
	return y;
}

float Node::getF()
{
	return f;
}

float Node::getG()
{
	return g;
}

float Node::getH()
{
	return h;
}

void Node::setParent(Node* node)
{
	parent = node;
}

Node* Node::getParent()
{
	return parent;
}


bool Node::sameCoordinates(Node* node)
{
		if(node->x == x && node->y == y) return true;
		else return false;
}

int Node::getSuccessors(Node* parentNode)
{
	return 0;
}

void Node::printInfo()
{
	cout << "Coordinates ->   X: " << x << "  Y: " << y << endl;
   	cout << "g = " << g << endl;
	cout << "h = " << h << endl;
	cout << "f = " << f << endl;
	if(parent != 0)
	{
		cout << "Parent coordinates ->   X: " << parent->getX() << "  Y: " << parent->getY() << endl;
	}
	else
	{
		cout << "It has not parent" << endl;
	}

}
